package com.qk.controller;

import com.qk.commen.PageResult;
import com.qk.commen.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    /**
     * 1. 活动列表查询
     */
    @GetMapping
    public Result list(ActivityDto activityDto) {
        PageResult<Activity> list = activityService.list(activityDto);
        return Result.success(list);
    }
    /**
     * 2. 活动删除
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }
    /**
     * 3. 活动添加
     */
    @PostMapping
    public Result add(@RequestBody Activity activity) {
        log.info("添加活动: {}", activity);
        activityService.add(activity);
        return Result.success();
    }
    /**
     * 4. 活动查询根据id
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }
    /**
     * 5. 活动修改
     */
    @PutMapping
    public Result update(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }
    /**
     * 6. 查询指定类型活动
     */
    @GetMapping("/type/{type}")
    public Result type(@PathVariable  Integer type){
        List<Activity> listType = activityService.listType(type);
        return Result.success(listType);
    }

}
